#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int S = (1 << 20) + 10;
const int N = 22;

int f[S], g[S];
int n, wl[N], wr[N], lg[S], m, vl[N], vr[N];
char s[N];
vec pot1, pot2;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in;
	rep(i, 0, n - 1) {
		scanf("%s", s);
		rep(j, 0, n - 1)
			if(s[j] == '1')  wl[i] |= 1 << j, wr[j] |= 1 << i;
	} rep(i, 2, (1 << 20)) lg[i] = lg[i >> 1] + 1;
	rep(i, 0, n - 1) vl[i] = in;
	rep(i, 0, m - 1) vr[i] = in;
	int U = 1 << n; U--;
	rep(s, 0, U) {
		f[s] = 1; g[s] = 0; int val = 0; if(s == 0) { pot1.eb(0); continue; }
		rep(i, 0, n - 1)
			if(s >> i & 1)
				f[s] &= f[s ^ 1 << i], val += vl[i];
		int x = s & -s; g[s] = g[s ^ x] | wl[lg[x]];
		f[s] &= __builtin_popcount(g[s]) >= __builtin_popcount(s);
		if(f[s]) pot1.eb(val);
	}
	U = 1 << m; U--;
	rep(s, 0, U) {
		f[s] = 1; g[s] = 0; int val = 0; if(s == 0) { pot2.eb(0); continue; }
		rep(i, 0, m - 1)
			if(s >> i & 1)
				f[s] &= f[s ^ 1 << i], val += vr[i];
		int x = s & -s; g[s] = g[s ^ x] | wr[lg[x]];
		f[s] &= __builtin_popcount(g[s]) >= __builtin_popcount(s);
		if(f[s]) pot2.eb(val);
	}
	sort(pot1.begin(), pot1.end()); sort(pot2.begin(), pot2.end(), greater < int >());
	int T = in; ll ans = 0;
	auto it = pot2.begin(); 
	for(auto v : pot1) {
		while(it != pot2.end() && *it + v >= T) it++;
		ans += it - pot2.begin();
	} printf("%lld\n", ans);
	return 0;
}
